#include "GraphicEngine.h"

#include "event_manager.h"

GraphicEngine::GraphicEngine()
	: myDevice       (irr::createDevice(irr::video::EDT_OPENGL,irr::core::dimension2d<irr::u32>(800,600),32))
	, myDriver       (myDevice->getVideoDriver())
	, myEnvironment  (myDevice->getGUIEnvironment())
	, mySceneManager (myDevice->getSceneManager())
	, handle_camera  (NULL)
{
	myDevice->setWindowCaption( L"Vie Artificielle" );

	handle_camera = new CameraHandle  ( *mySceneManager->addCameraSceneNode (0, irr::core::vector3df(0, 0,  -30)), 0, -10);
	mySceneManager->addLightSceneNode (0, irr::core::vector3df(0, 100, 0), irr::video::SColorf(1.0f, 0.0f, 0.0f));
	mySceneManager->setAmbientLight   (irr::video::SColorf(0.3f, 0.3f, 0.3f));

	myDevice->setEventReceiver( new GraphicEngineEventManager( *handle_camera) );
}

GraphicEngine::~GraphicEngine()
{
	myDevice->drop();
}

void GraphicEngine::RenderOnce()
{
	myDriver->beginScene (true, true, irr::video::SColor(200,200,200,255));
	
	mySceneManager->drawAll ();
	myEnvironment->drawAll();

	myDriver->endScene ();	

	myDevice->run();
}